package cn.edu.zafu.bigdata.bd121.im.common;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * 处理服务器端用户输入
 *
 * @author 202211090121
 */
public class HandleUserInput implements Runnable {

    /**
     * 发送消息的输出流
     */
    public PrintWriter out;

    /**
     * 接收用户输入
     */
    private final Scanner sc = new Scanner(System.in);

    /**
     * 接收用户输入并发送给客户端
     */
    @Override
    public void run() {
        while (true) {
            if (sc.hasNextLine()) {
                String input = sc.nextLine();
                out.println(input);
                out.flush();
            }
        }
    }

    public HandleUserInput(Socket socket) throws IOException {
        this.out = new PrintWriter(socket.getOutputStream(), true);
    }
}
